/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024 —03 —18
 * Time: 20:26
 */
public class OutClass {
    private int a;
    static int b ;
    String c = "打印的是外部类的成员变量c";
    //普通成员方法
    public void methodA(){
        a = 10;
        System.out.println(a);//10
    }
    public static void methodB(){
        b  = 20;
        System.out.println(b);//20
    }

    static class InnerClass{
        int c;
        public void methodInner(){
           // a = 100;
            b = 200;
            //methodA();    报错的原因静态内部类只能访问外部类的静态成员变量和静态成员方法
            c = 100;
            System.out.println(c);
            methodB();
            System.out.println(" 打印结果是不是100和20 "  );
            //System.out.println(OutClass.this.c);
        }
    }

    public static void main(String[] args) {
        OutClass outClass = new OutClass();
        System.out.println(outClass.a);//0
        System.out.println(outClass.b);//0
        System.out.println(outClass.c);//"打印的是外部类的成员变量c"
        outClass.methodA();//10
        outClass.methodB();//20


        //System.out.println("访问实例内部类");
        System.out.println("访问静态内部类");
        OutClass.InnerClass innerClass = new OutClass.InnerClass();//实例化了一个静态内部类
        innerClass.methodInner( );
        //实际上是拆分了OutClass outClass = new OutClass();
        //                             再outClass.new InnerClass();
        //实例化了一个内部类
       // OutClass.InnerClass innerClass = outClass.new InnerClass();
        //innerClass.methodInner();//10  20  100  打印的是外部类的成员变量c"
    }


}
